package com.gxa.jjty.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.mapper.VBillDetailsMapper;
import com.gxa.jjty.admin.service.VBillDetailsService;
import com.gxa.jjty.core.pojo.VBillDetails;
import com.gxa.jjty.core.pojo.VSRoyalty;
import com.gxa.jjty.core.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.entity.Example;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
@Transactional(rollbackFor = Throwable.class)
public class VBillDetailsServiceImpl extends BaseServiceImpl<VBillDetails> implements VBillDetailsService {

    @Autowired
   Mapper<VBillDetails> billDetailsMapper;

    @Override
    public PageInfo<VBillDetails> selectVBillDetails(Integer page, Integer size, Date startTime, Date endTime, String orderNumber, String name, String payType) {

       /* SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd ");
        String sTime = formatter.format(startTime);
        String eTime = formatter.format(endTime);*/
        PageHelper.startPage(page,size);
        Example example = new Example(VBillDetails.class);
        Example.Criteria criteria = example.createCriteria();
        if (name != null && name !=""){
            criteria.andLike("name","%"+name+"%");
        }
        if (orderNumber != null && orderNumber !=""){
            criteria.andLike("orderNumber","%"+orderNumber+"%");
        }
        if (startTime != null  && endTime != null ){

            criteria.andBetween("riseTime",startTime,endTime);
        }
        if (payType != null && payType !=""){
            criteria.andEqualTo("payType",payType);
        }
        example.orderBy("riseTime").desc();
        List<VBillDetails> vBillDetails = billDetailsMapper.selectByExample(example);
        PageInfo<VBillDetails> of = PageInfo.of(vBillDetails);
        return  of;


    }
}
